Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chip] Add clickable property #11613

Merged
merged 11 commits into from
May 31, 2018
Merged

[Chip] Add clickable property #11613

merged 11 commits into from
May 31, 2018

Conversation

vilvaathibanpb
Copy link
Contributor

@vilvaathibanpb vilvaathibanpb commented May 28, 2018

Have added a new prop for the Chip - 'clickable' which takes a boolean as input and makes the Chip clickable irrespective of the component type

Closes #11502

...other
} = this.props;

const className = classNames(
classes.root,
{ [classes.clickable]: onClick },
{ [classes.clickable]: onClick || clickable},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clickable }

@@ -239,10 +240,15 @@ Chip.propTypes = {
* @ignore
*/
tabIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
/**
* Boolean to determine if the chip should be clickable.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow the wording of other bool props. ('If true, ...')

@mbrookes mbrookes changed the title Fixed Chip should be styled clickable when component is [[Chip] Add clickable prop May 28, 2018
@mbrookes mbrookes changed the title [[Chip] Add clickable prop [Chip] Add clickable prop May 28, 2018
};

Chip.defaultProps = {
component: 'div',
clickable: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing comma, and clickable goes before component.

@mbrookes
Copy link
Member

run yarn lint, or npm run lin to see lint issues.

@oliviertassinari oliviertassinari added new feature New feature or request component: chip This is the name of the generic UI component, not the React module! labels May 28, 2018
@mbrookes
Copy link
Member

mbrookes commented May 28, 2018

You'll also need to run yarn docs:api / npm run docs:api to update the API docs markdown from the source code comments. Something I nearly always forget! 😅

Oh, and update the typescript definition (.d.ts file) please.

@vilvaathibanpb
Copy link
Contributor Author

@mbrookes Hi, I am done with other comments, but not able to run yarn docs:api / npm run docs:api. I face an error "module not found 'deepmerge'". Even if I install deepmerge, I get further errors. Can you help me in this?

@mbrookes
Copy link
Member

Are you using yarn or npm?

Did you run yarn or npm install? For npm 6 you can try npm ci to do a clean install.

@vilvaathibanpb
Copy link
Contributor Author

Hi I am using npm 5.6.0. Yea I did npm install right after I cloned the repo. And after making changes I tried both "yarn docs:api" and "npm run docs:api". But same error. PFA screenshot
screen shot 2018-05-29 at 5 25 34 pm

@mbrookes
Copy link
Member

No idea, but since you have yarn, try running yarn && yarn docs:api.

Failing that, I'll do it push to your repo.

@vilvaathibanpb
Copy link
Contributor Author

@mbrookes Wow. That worked. Hopefully its time for me to move to yarn from npm ;-). I guess PR is good right now. Please review it

@@ -242,6 +248,7 @@ Chip.propTypes = {
};

Chip.defaultProps = {
clickable: false,
Copy link
Member

@oliviertassinari oliviertassinari May 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the clickable property have a higher priority than the onClick detection logic?
Meaning, what's the output of <Chip clickable={false} onClick={() => ()} />?

Copy link
Contributor Author

@vilvaathibanpb vilvaathibanpb May 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oliviertassinari I feel clickable should have low priority than OnClick. The output of above will still be clickable as per the below code: { [classes.clickable]: onClick || clickable }, if onclick is present, it will be clickable at any cost. Only when onClick is not present, clickable comes into the picture.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oliviertassinari This is only affecting the styling (and the description should perhaps reflect that), but requiring the prop to be set in order for a Chip with onClick to appear clickable seems counter-intuitive to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but requiring the prop to be set in order for a Chip with onClick to appear clickable seems counter-intuitive to me.

@mbrookes I was asking the question in a context where defaultProps.clickable = null.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. So being able to set clickable={somethingFalse} when a Chip has an onClick() handler but other conditions mean that it won't act on the click?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oliviertassinari I feel defaultProps.clickable = null also would work fine. still false makes better sense, as we have kept props type as boolean. Also, in terms of functionality, nothing changes in either way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbrookes Couldn't understand your question clearly. But to explain, if we have 'onClick' hander, 'clickable' doesn't affect and the chip is always clickable. when 'onClick' is not present, then the value of 'clickable' determine if the chip is clickable

Copy link
Member

@mbrookes mbrookes May 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vilvaathibanpb I was just clarifying with @oliviertassinari if I understood correctly the benefit of defaultProps.clickable = null combined with clickable having priority.

Let me rephrase it as a direct question: @oliviertassinari What do you see as the main benefit for null as the default?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you see as the main benefit for null as the default?

The advantage is that it's allowing people to control the clickable state, but still, being able to rely on the onClick detection logic if they wish. But I'm fine either way. The current approach is simple too.

@oliviertassinari oliviertassinari changed the title [Chip] Add clickable prop [Chip] Add clickable property May 29, 2018
/**
* If `true`, the chip will be clickable.
* By default, the chip will not be clickable.
*/
Copy link
Member

@mbrookes mbrookes May 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming we keep the current logic, the wording needs to be something like:

"If true, the chip will appear clickable, and will raise when pressed, even if the onClick property is not defined. This can be used, for example, along with the component property to indicate an anchor Chip is clickable."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And an example in the docs would be good...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbrookes Have changed the comments and added an example as well. Please let me know if any other changes are required

@@ -30,6 +30,7 @@ function Chips(props) {
return (
<div className={classes.root}>
<Chip label="Basic Chip" className={classes.chip} />
<Chip label="Clickable without onClick Chip" clickable className={classes.chip} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbrookes Unless I'm missing something, by demo, the point was to showcase a link chip no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. For buttons we link to the page section id, so a link to '#chip' would do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. you also want me to add component 'a' ? or just adding a 'href="#chip"' will do? And what title will be suitable for it? "Link" or "Clickable without onClick chip (Link)".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever use case you're solving for, and as short a name as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbrookes I have added link to the Chip and also made the name as Clickable Link Chip. Please let me know if I have to make any more changes

label="Clickable Link Chip"
className={classes.chip}
clickable
/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please could you put this last in the list of Chips?

In terms of prop ordering, lets put the added props at the end for clarity:

      <Chip
        label="Clickable Link Chip"
        className={classes.chip}
        component="a"
        href="#chip"
        clickable
      />

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbrookes Have rearranged the props. Any other suggestions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please could you put this last in the list of Chips?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbrookes Sorry I just missed that. Have moved it to the last in the list of Chips. Thanks a lot for your patience as I make so many issues.

@vilvaathibanpb
Copy link
Contributor Author

@mbrookes Please review and let me know if any further changes required. Hopefully, everything is done 👍

@mbrookes
Copy link
Member

@vilvaathibanpb So far so good, but it looks like you still need to fix the underline?

@vilvaathibanpb
Copy link
Contributor Author

@mbrookes underline as in ? U dont need underline for a Link chip?

@vilvaathibanpb
Copy link
Contributor Author

@mbrookes and @oliviertassinari Ideally this text decoration should be none for chip in the root level right? Not just for clickable

@vilvaathibanpb
Copy link
Contributor Author

@mbrookes Can you check now, please?

@oliviertassinari
Copy link
Member

For some reason, the new chip link demo isn't keyboard accessible.

@vilvaathibanpb
Copy link
Contributor Author

@oliviertassinari Sure? Because I was able to access the chip with keyboard (Tab key). I use Mac - chrome 64

@vilvaathibanpb
Copy link
Contributor Author

@oliviertassinari Sorry my bad. If you notice, even Basic chip is not accessible through keyboard. Only when onclick or onDelete is present, the chips are keyboard accessible

@vilvaathibanpb
Copy link
Contributor Author

@oliviertassinari Have made the chip accessible through the keyboard. Check now, please.

@mbrookes mbrookes merged commit 1bdf0c2 into mui:master May 31, 2018
@vilvaathibanpb
Copy link
Contributor Author

This was my first Open source contribution and i learnt so much about detailing and looking for various checks. Thank you so much for your patience @mbrookes and @oliviertassinari

@mbrookes
Copy link
Member

@vilvaathibanpb Thanks for seeing this through. I appreciate it was a lot of work for a small change, but hopefully that gives some insight into how much care has gone into the rest of the library. (Which is not to say it's perfect by any means, but we try our best! 😅)

acroyear pushed a commit to acroyear/material-ui that referenced this pull request Jul 14, 2018
@zachrickards
Copy link

This would be much better if having clickable={false} OnClick={() => { do something}}. I would like that to disable the click. As of right now, if you have an onclick, clickable does absolutely nothing. The feature that would be much better if styling and making the onclick not function not work. As clickable false, seems like the "chip" should be disabled

@vilvaathibanpb
Copy link
Contributor Author

@mbrookes Should we consider @zachrickards request?

@oliviertassinari
Copy link
Member

@vilvaathibanpb This sounds like a valid request to me!

@mbrookes
Copy link
Member

mbrookes commented Sep 29, 2018

@zachrickards Please open an issue for it so it doesn't get lost. Better still, would you like to work on it?

@vilvaathibanpb
Copy link
Contributor Author

vilvaathibanpb commented Sep 29, 2018

@oliviertassinari and @mbrookes I can pick it up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: chip This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants